package aod.android.com.bernay.mine.activity;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;

import java.io.IOException;

import aod.android.com.bernay.R;
import aod.android.com.bernay.base.BernayBaseActivity;
import aod.android.com.bernay.http.BernayApi;
import aod.android.com.bernay.http.BernayCallback;
import aod.android.com.bernay.mine.module.AboutUsBean;
import aod.android.com.bernay.util.SharePreUtils;
import aod.android.com.bernay.util.Utils;
import chen.lion.hilib.util.LogUtils;
import chen.lion.hilib.view.bind.HiView;

/**
 * @author crated by zhixianuanyang on 2019/4/3 12:21
 * @Email jamesKing0812@gmail.com
 */
public class AboutUsActivity extends BernayBaseActivity implements View.OnClickListener {

    @HiView(R.id.ll_hotline)
    RelativeLayout layoutHotline;

    @HiView(R.id.ll_customer)
    RelativeLayout layoutCustomer;

    @HiView(R.id.ll_business)
    RelativeLayout layoutBusiness;

    @HiView(R.id.ll_mall)
    RelativeLayout layoutMall;

    @HiView(R.id.tv_hotline)
    TextView mHotline;

    @HiView(R.id.tv_customer)
    TextView mCustomere;

    @HiView(R.id.tv_business)
    TextView mBusiness;

    @HiView(R.id.tv_mall)
    TextView mMall;

    @Override
    protected int initLayout() {
        return R.layout.activity_about_us;
    }

    @Override
    protected void initData() {
        initTitle(getString(R.string.about_us));
        getAboutUsData();
        layoutHotline.setOnClickListener(this);
        layoutCustomer.setOnClickListener(this);
        layoutBusiness.setOnClickListener(this);
        layoutMall.setOnClickListener(this);
    }




    /**
     * 获取关于我们数据
     */
    private void getAboutUsData() {
        String userId = SharePreUtils.newInstance(AboutUsActivity.this).getUserId();
        String token =  SharePreUtils.newInstance(AboutUsActivity.this).getToken();
        BernayApi.http().getAboutUs(userId, token, new BernayCallback() {
            @Override
            public void onJsonData(String json) {
                Gson gson = new Gson();
                AboutUsBean aboutUsBean = gson.fromJson(json, AboutUsBean.class);
                if (1 == aboutUsBean.getStatus()){
                    mHotline.setText(aboutUsBean.getData().get(0).getLinkClient());
                    mCustomere.setText(aboutUsBean.getData().get(0).getLinkCompany());
                    mBusiness.setText(aboutUsBean.getData().get(0).getLinkCustomer());
                    mMall.setText(aboutUsBean.getData().get(0).getMallUrl());
                }
            }

            @Override
            public void onHttpFailure(IOException e) {
                LogUtils.json(new Gson().toJson(e));
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_hotline:
               Utils.callPhone(this,mHotline.getText().toString());
                break;
            case R.id.ll_customer:
                Utils.callPhone(this,mCustomere.getText().toString());
                break;
            case R.id.ll_business:
                Utils.callPhone(this,mBusiness.getText().toString());
                break;
            case R.id.ll_mall:
                Utils.callPhone(this,mMall.getText().toString());
                break;
        }
    }
}
